package webStudio7i.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import webStudio7i.excepcion.DAOExcepcion;
import webStudio7i.modelo.Alquiler;
import webStudio7i.modelo.Sala;
import webStudio7i.modelo.Servicio;
import webStudio7i.negocio.AlquilerBll;
import webStudio7i.negocio.ServiciosBll;

/**
 * Servlet implementation class ConsultaReservas
 */
public class ConsultaReservaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ConsultaReservaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
				String fecIni = request.getParameter("txtFechaIni");
				String fecFin = request.getParameter("txtFechaFin");
				int idSala = Integer.parseInt((request.getParameter("cboSalas").trim()));
				try {
					Alquiler alq = new Alquiler(); 
					alq.setFechahora_fin(fecFin);
					alq.setFechahora_inicio(fecIni);
					Sala sala = new Sala(); 
					sala.setIdsala(idSala);
					alq.setObjSala(sala);
					// Validando la existencia de un servicio
					AlquilerBll objAlqBll = new AlquilerBll();
					Collection<Alquiler> lstAlq =	objAlqBll.ConsultarAlquiler(alq);
					request.setAttribute("lstAlquiler", lstAlq);
					RequestDispatcher rd = request.getRequestDispatcher("/ConsultaReservas.jsp");
					rd.forward(request, response);
					return;
				} catch (DAOExcepcion e) {
					e.printStackTrace();
				}
	}

}
